<template>
  <div class="newsInfo-container">
    <div class="hd">
      <h2>{{newsInfo.title}}</h2>
      <p>
        <span>发表时间：{{newsInfo.add_time | dateFormat('YYYY/MM/DD HH:mm:ss')}}</span>
        <span>点击量：{{newsInfo.click}}</span>
      </p>
    </div>
    <article v-html="newsInfo.content"></article>
    <comment :id="id" />
  </div>
</template>

<script>
import { Toast } from 'vant'
import comment from '@/components/Comment.vue'
export default {
  data() {
    return {
      id: this.$route.params.id,
      newsInfo: {}
    }
  },
  created() {
    this.getNewsInfo()
  },
  methods: {
    getNewsInfo() {
      this.axios.get('/news/newsInfo', { params: { _id: this.id } }).then(res => {
        if (res.data.code == 0) {
          Toast(res.data.msg)
        } else if (res.data.code == 1) {
          this.newsInfo = res.data.newsInfo
        }
      })
    }
  },
  components: { comment }
}
</script>

<style lang="scss">
.newsInfo-container {
  .hd {
    padding: 0 0.4rem;
    h2 {
      margin: 0.2rem 0;
    }
    p {
      display: flex;
      justify-content: space-between;
    }
  }
  article {
    img {
      width: 90vw;
    }
    width: 90vw;
    margin: 0 auto;
  }
}
</style>